package com.ophiux.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestThreadPool {
    public static void main(String[] args) {
        //一个线程池有5个线程可供调用
        ExecutorService threadPool = Executors.newFixedThreadPool(5);
        //一个线程池只有一个线程可以调用
        ExecutorService threadPool1 = Executors.newSingleThreadExecutor();
        //一个线程池可以有n个线程可以调用，可以扩容
        ExecutorService threadPool2 = Executors.newCachedThreadPool();
        try {
            for (int i = 0; i < 10; i++) {
//                threadPool2.execute(() -> {
//                    System.out.println(Thread.currentThread().getName() + "\t办理业务");
//                });

                threadPool2.execute(new Runnable() {
                    @Override
                    public void run() {
                        System.out.println(Thread.currentThread().getName() + "\t办理业务");
                    }
                });

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            threadPool.shutdown();
        }
    }
}
